chunk options
CSS for scrollable output & Header colors
Turning scientific / Exponential numbers off
options(scipen = 999)data from: from: https://www.kaggle.com/sudalairajkumar/covid19-in-india
library(tidyverse)
library(ggthemes)
library(lubridate)
library(gghighlight)
library(streamgraph)
library(plotly)
library(highcharter)
library(glue)
library(gghalves)
library(htmlwidgets)
library(RColorBrewer)
library(viridis)
library(ggtext)
theme_viny_bright <- function(){
library(ggthemes)
ggthemes::theme_fivethirtyeight() %+replace%
theme(
axis.title = element_text(),
axis.text = element_text(size = 13),
legend.text = element_text(size = 10),
panel.background = element_rect(fill = "white"),
plot.background = element_rect(fill = "white"),
strip.background = element_blank(),
legend.background = element_rect(fill = NA),
legend.key = element_rect(fill = NA),
plot.title = element_text(hjust = 0.5,
size = 19,
face = "bold"),
plot.subtitle = element_text(hjust = 0.5, colour = "maroon")
)
}
theme_set(theme_viny_bright())df_ind <- read.csv("../data kaggle/covid_19_india.csv")
df_indstr(df_ind)'data.frame': 9291 obs. of 9 variables:
$ ï..Sno : int 1 2 3 4 5 6 7 8 9 10 ...
$ Date : chr "30/01/20" "31/01/20" "01/02/20" "02/02/20" ...
$ Time : chr "6:00 PM" "6:00 PM" "6:00 PM" "6:00 PM" ...
$ State.UnionTerritory : chr "Kerala" "Kerala" "Kerala" "Kerala" ...
$ ConfirmedIndianNational : chr "1" "1" "2" "3" ...
$ ConfirmedForeignNational: chr "0" "0" "0" "0" ...
$ Cured : int 0 0 0 0 0 0 0 0 0 0 ...
$ Deaths : int 0 0 0 0 0 0 0 0 0 0 ...
$ Confirmed : int 1 1 2 3 3 3 3 3 3 3 ...
summary(df_ind) ï..Sno Date Time State.UnionTerritory ConfirmedIndianNational
Min. : 1 Length:9291 Length:9291 Length:9291 Length:9291
1st Qu.:2324 Class :character Class :character Class :character Class :character
Median :4646 Mode :character Mode :character Mode :character Mode :character
Mean :4646
3rd Qu.:6968
Max. :9291
ConfirmedForeignNational Cured Deaths Confirmed
Length:9291 Min. : 0 Min. : 0.0 Min. : 0.0
Class :character 1st Qu.: 152 1st Qu.: 2.0 1st Qu.: 538.5
Mode :character Median : 4308 Median : 66.0 Median : 6832.0
Mean : 78633 Mean : 1487.6 Mean : 91839.8
3rd Qu.: 57727 3rd Qu.: 926.5 3rd Qu.: 78856.0
Max. :1737080 Max. :47827.0 Max. :1859367.0
df_ind <- df_ind %>%
mutate(Date = lubridate::dmy(Date),
State.UnionTerritory = as.factor(State.UnionTerritory),
# Time = lubridate::parse_date_time(Time, "I:M p"),
Time = as.factor(Time),
ConfirmedIndianNational = as.integer(ConfirmedIndianNational),
ConfirmedForeignNational = as.integer(ConfirmedForeignNational)
)
df_indsummary(df_ind) ï..Sno Date Time State.UnionTerritory ConfirmedIndianNational
Min. : 1 Min. :2020-01-30 10:00 AM: 27 Kerala : 315 Min. : 0.00
1st Qu.:2324 1st Qu.:2020-05-26 5:00 PM : 899 Delhi : 283 1st Qu.: 1.00
Median :4646 Median :2020-07-30 6:00 PM : 600 Rajasthan : 282 Median : 3.00
Mean :4646 Mean :2020-07-29 7:30 PM : 56 Haryana : 281 Mean : 12.19
3rd Qu.:6968 3rd Qu.:2020-10-04 8:00 AM :7653 Uttar Pradesh: 281 3rd Qu.: 13.00
Max. :9291 Max. :2020-12-09 8:30 PM : 28 Ladakh : 278 Max. :177.00
9:30 PM : 28 (Other) :7571 NA's :8845
ConfirmedForeignNational Cured Deaths Confirmed
Min. : 0.000 Min. : 0 Min. : 0.0 Min. : 0.0
1st Qu.: 0.000 1st Qu.: 152 1st Qu.: 2.0 1st Qu.: 538.5
Median : 0.000 Median : 4308 Median : 66.0 Median : 6832.0
Mean : 1.496 Mean : 78633 Mean : 1487.6 Mean : 91839.8
3rd Qu.: 1.000 3rd Qu.: 57727 3rd Qu.: 926.5 3rd Qu.: 78856.0
Max. :14.000 Max. :1737080 Max. :47827.0 Max. :1859367.0
NA's :8845
df_ind <- df_ind %>%
mutate(CFR = round(Deaths / Confirmed * 100, digits = 2),
Recovery_Rate = round(Cured / Confirmed * 100, digits = 2))
df_inddf_ind <- df_ind %>%
group_by(State.UnionTerritory) %>%
mutate(Daily_confirmed = Confirmed - lag(Confirmed, default = 0),
Daily_deaths = Deaths - lag(Deaths, default = 0),
Daily_cured = Cured - lag(Cured, default = 0)) %>%
ungroup()
df_inddf_ind$State.UnionTerritory %>%
table().
Andaman and Nicobar Islands Andhra Pradesh
259 273
Arunachal Pradesh Assam
251 253
Bihar Cases being reassigned to states
263 60
Chandigarh Chandigarh***
265 1
Chhattisgarh Dadar Nagar Haveli
266 37
Dadra and Nagar Haveli and Daman and Diu Daman & Diu
181 1
Delhi Goa
283 259
Gujarat Haryana
265 281
Himachal Pradesh Jammu and Kashmir
264 276
Jharkhand Karnataka
253 276
Kerala Ladakh
315 278
Madhya Pradesh Maharashtra
264 275
Maharashtra*** Manipur
1 261
Meghalaya Mizoram
240 260
Nagaland Odisha
207 269
Puducherry Punjab
267 275
Punjab*** Rajasthan
1 282
Sikkim Tamil Nadu
200 278
Telangana Telangana***
45 1
Telengana Telengana***
236 1
Tripura Unassigned
247 3
Uttar Pradesh Uttarakhand
281 270
West Bengal
267
df_ind %>%
filter(State.UnionTerritory %in% c("Chandigarh***","Maharashtra***","Telangana***","Telengana***"))This is the code to replace *** States with original which we are not gonna use
df_ind <- df_ind %>%
mutate(State.UnionTerritory = replace(State.UnionTerritory,
State.UnionTerritory %in% c("Telengana","Telengana***","Telangana***"),
"Telangana"),
State.UnionTerritory = replace(State.UnionTerritory,
State.UnionTerritory %in% "Maharashtra***",
"Maharashtra"),
State.UnionTerritory = replace(State.UnionTerritory,
State.UnionTerritory %in% "Chandigarh***",
"Chandigarh"),
State.UnionTerritory = replace(State.UnionTerritory,
State.UnionTerritory %in% "Punjab***",
"Punjab"),
# to get rid of old replaced levels from factor columns
State.UnionTerritory = as.character(State.UnionTerritory),
State.UnionTerritory = as.factor(State.UnionTerritory)
)
df_inddf_ind <- df_ind %>%
mutate(State.UnionTerritory = replace(State.UnionTerritory,
State.UnionTerritory %in% c("Telengana"),
"Telangana"),
State.UnionTerritory = replace(State.UnionTerritory,
State.UnionTerritory %in% c("Telengana***"),
"Telangana***"),
# to get rid of old replaced levels from factor columns
State.UnionTerritory = as.character(State.UnionTerritory),
State.UnionTerritory = as.factor(State.UnionTerritory)
)
df_inddf_ind %>%
pull(State.UnionTerritory) %>%
unique() [1] Kerala Telangana
[3] Delhi Rajasthan
[5] Uttar Pradesh Haryana
[7] Ladakh Tamil Nadu
[9] Karnataka Maharashtra
[11] Punjab Jammu and Kashmir
[13] Andhra Pradesh Uttarakhand
[15] Odisha Puducherry
[17] West Bengal Chhattisgarh
[19] Chandigarh Gujarat
[21] Himachal Pradesh Madhya Pradesh
[23] Bihar Manipur
[25] Mizoram Andaman and Nicobar Islands
[27] Goa Unassigned
[29] Assam Jharkhand
[31] Arunachal Pradesh Tripura
[33] Nagaland Meghalaya
[35] Dadar Nagar Haveli Cases being reassigned to states
[37] Sikkim Daman & Diu
[39] Dadra and Nagar Haveli and Daman and Diu Telangana***
[41] Maharashtra*** Chandigarh***
[43] Punjab***
43 Levels: Andaman and Nicobar Islands Andhra Pradesh Arunachal Pradesh Assam ... West Bengal
from: https://uidai.gov.in/images/state-wise-aadhaar-saturation.pdf
df_ind <- df_ind %>%
mutate(Population_State = case_when(State.UnionTerritory == "Kerala" ~ 35699443,
State.UnionTerritory == "Telangana" ~ 39362732,
State.UnionTerritory == "Delhi" ~ 18710922,
State.UnionTerritory == "Rajasthan" ~ 81032689,
State.UnionTerritory == "Uttar Pradesh" ~ 237882725,
State.UnionTerritory == "Haryana" ~ 28204692,
State.UnionTerritory == "Ladakh" ~ 289023,
State.UnionTerritory == "Tamil Nadu" ~ 77841267,
State.UnionTerritory == "Karnataka" ~ 67562686,
State.UnionTerritory == "Maharashtra" ~ 123144223,
State.UnionTerritory == "Punjab" ~ 30141373,
State.UnionTerritory == "Jammu and Kashmir" ~ 13606320,
State.UnionTerritory == "Andhra Pradesh" ~ 53903393,
State.UnionTerritory == "Uttarakhand" ~ 11250858,
State.UnionTerritory == "Odisha" ~ 46356334,
State.UnionTerritory == "Puducherry" ~ 1413542,
State.UnionTerritory == "West Bengal" ~ 99609303,
State.UnionTerritory == "Chhattisgarh" ~ 29436231,
State.UnionTerritory == "Chandigarh" ~ 1158473,
State.UnionTerritory == "Gujarat" ~ 63872399,
State.UnionTerritory == "Himachal Pradesh" ~ 7451955,
State.UnionTerritory == "Madhya Pradesh" ~ 85358965,
State.UnionTerritory == "Bihar" ~ 124799926,
State.UnionTerritory == "Manipur" ~ 3091545,
State.UnionTerritory == "Mizoram" ~ 1239244,
State.UnionTerritory == "Andaman and Nicobar Islands " ~ 417036,
State.UnionTerritory == "Goa" ~ 1586250,
State.UnionTerritory == "Assam" ~ 35607039,
State.UnionTerritory == "Jharkand" ~ 38593948,
State.UnionTerritory == "Arunachal Pradesh" ~ 1570458,
State.UnionTerritory == "Tripura" ~ 4169794,
State.UnionTerritory == "Nagaland" ~ 2249695,
State.UnionTerritory == "Meghalaya" ~ 3366710,
State.UnionTerritory == "Dadar Nagar Haveli" ~ 615724,
State.UnionTerritory == "Sikkim" ~ 690251,
State.UnionTerritory == "Daman & Diu" ~ 615724)
)
df_inddf_ind %>%
select(- ï..Sno) %>%
gather(key = "Daily_cases_type", value = "Cases_counts",
-c("State.UnionTerritory", "Date", "Time", "Population_State",
"ConfirmedIndianNational", "ConfirmedForeignNational", "CFR"
)) %>%
pull(Daily_cases_type) %>%
table().
Confirmed Cured Daily_confirmed Daily_cured Daily_deaths Deaths
9291 9291 9291 9291 9291 9291
Recovery_Rate
9291
df_ind_stacked_daily <- df_ind %>%
select(- c("ï..Sno","Confirmed","Cured","Deaths")) %>%
gather(key = "Daily_cases_type", value = "Daily_cases_counts",
-c("State.UnionTerritory", "Date", "Time", "Population_State",
"ConfirmedIndianNational", "ConfirmedForeignNational", "CFR","Recovery_Rate"
))
df_ind_stacked_dailydf_ind_stacked_cum <- df_ind %>%
select(- c("ï..Sno","Daily_confirmed","Daily_cured","Daily_deaths")) %>%
gather(key = "Cases_type", value = "Cases_counts",
-c("State.UnionTerritory", "Date", "Time", "Population_State",
"ConfirmedIndianNational", "ConfirmedForeignNational", "CFR","Recovery_Rate"
))
df_ind_stacked_cumdf_ind_stacked_rates <- df_ind %>%
select(- c("ï..Sno") )%>%
gather(key = "Rate_type", value = "Rate_value",
-c("State.UnionTerritory", "Date", "Time", "Population_State",
"ConfirmedIndianNational", "ConfirmedForeignNational",
"Daily_confirmed", "Daily_cured", "Daily_deaths",
"Confirmed", "Cured", "Deaths"))
df_ind_stacked_ratesdf_ind %>%
filter(Date == max(Date, na.rm = TRUE)) %>%
highcharter::data_to_hierarchical(
group_vars = c(State.UnionTerritory),
size_var = Confirmed,
# colors = getOption("hicharter.color_palette")
) %>%
hchart(type = "treemap")df_ind %>%
filter(Date == max(Date, na.rm = TRUE)) %>%
hchart(type = "treemap",
hcaes(x = State.UnionTerritory, value = Confirmed, color = Confirmed)
) %>%
hc_colorAxis(stops = color_stops(colors = viridis::inferno(10))) %>%
hc_title(text = "Relative size of Cumulative Confirmed Cases of Indian State/UT", align = "center")df_ind %>%
filter(Date == max(Date, na.rm = TRUE)) %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, Confirmed)) %>%
ggplot(aes(x = Confirmed, y = State.UnionTerritory, fill = State.UnionTerritory)) +
geom_col() +
theme_classic() +
theme(legend.position = "none",
axis.ticks.y = element_blank(),
axis.line.y = element_blank()) +
scale_x_continuous(labels = scales::comma_format()) +
labs(title = glue("Cumulative Confirmed Cases as of {max(df_ind$Date, na.rm = TRUE)}"),
caption = "Created by ViSa !!")df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
ggplot(aes(x = Date, y = Confirmed, col = State.UnionTerritory)) +
geom_line(size = 1.1) +
gghighlight(Confirmed > 500000) +
labs(title = "States highlighted above confirmed cases: 500,000",
subtitle = "Maharashtra tops the list",
caption = "Created by ViSa !!")df_ind %>%
filter(Date > as.Date("2020-04-01")) %>%
streamgraph(date = "Date", key = "State.UnionTerritory", value = "Confirmed") %>%
sg_fill_brewer("PuOr") %>%
sg_title("Confirmed cases State wise relative growth since Apr")df_ind %>%
group_by(State.UnionTerritory) %>%
summarise(max_daily_Case = max(Daily_confirmed)) %>%
ungroup()df_ind %>%
group_by(State.UnionTerritory) %>%
summarise(max_daily_Case = max(Daily_confirmed)) %>%
ungroup() %>%
summarise(max_of_max = max(max_daily_Case))df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
ggplot(aes(x = Date, y = Daily_confirmed, col = State.UnionTerritory)) +
geom_line(size = .8) +
gghighlight(Daily_confirmed > 4000) +
labs(title = "Highlighted States with daily confirmed cases > 4000",
caption = "Created by ViSa !!")df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
ggplot(aes(x = Date, y = Daily_confirmed, col = State.UnionTerritory)) +
geom_line() +
scale_y_log10() +
labs(title = "States highlighted with Daily Confirmed cases > 5000",
subtitle = "In log scale",
caption = "Created by ViSa !!",
y = "log of Daily Confirmed") gghighlight(Daily_confirmed > 5000)$predicates
<list_of<quosure>>
[[1]]
<quosure>
expr: ^Daily_confirmed > 5000
env: global
$n
NULL
$max_highlight
[1] 5
$unhighlighted_params
list()
$use_group_by
NULL
$use_direct_label
NULL
$label_key
<quosure>
expr: ^NULL
env: empty
$label_params
$label_params$fill
[1] "white"
$keep_scales
[1] FALSE
$calculate_per_facet
[1] FALSE
attr(,"class")
[1] "gg_highlighter"
df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
filter(State.UnionTerritory != "Telangana") %>%
ggplot(aes(x = Date, y = Daily_confirmed, col = State.UnionTerritory)) +
geom_line(size = .8) +
gghighlight(Daily_confirmed > 4000) +
labs(title = "States highlighted (- Telangana)",
subtitle = "daily confirmed > 4000",
caption = "Created by ViSa !!")df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
filter(State.UnionTerritory %in% (df_ind %>%
filter(Date == max(Date, na.rm = TRUE)) %>%
top_n(n = 10, wt = Confirmed) %>%
pull(State.UnionTerritory))
) %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, Daily_confirmed)) %>%
ggplot(aes(x = State.UnionTerritory, y = Daily_confirmed,
fill = State.UnionTerritory, col = State.UnionTerritory)) +
geom_half_boxplot(side = "l", alpha = 0.7) +
geom_half_violin(side = "r", alpha = 0.7) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90),
legend.position = "none") +
labs(title = "Daily Confirmed Cases Distribution of top 10 States",
subtitle = "Maharashtra with highest median and point values",
caption = "created by ViSa !!")df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
filter(State.UnionTerritory %in% (df_ind %>%
filter(Date == max(Date, na.rm = TRUE)) %>%
top_n(n = 10, wt = Deaths) %>%
pull(State.UnionTerritory))
) %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, Daily_deaths)) %>%
ggplot(aes(x = State.UnionTerritory, y = Daily_deaths,
fill = State.UnionTerritory, col = State.UnionTerritory)) +
geom_half_boxplot(side = "l", alpha = 0.7) +
geom_half_point(side = "r") +
# geom_jitter(alpha = 0.7) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90),
legend.position = "none") +
labs(title = "Daily Deaths Distribution of top 10 States",
subtitle = "Maharashtra with highest median and point values",
caption = "created by ViSa !!")CFR
df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
ggplot(aes(x = Date, y = CFR, col = State.UnionTerritory)) +
geom_line() +
labs(title = "CFR of Indian States from beignning",
y = "CFR (%)")df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
filter(Date > ymd("2020-05-31")) %>%
ggplot(aes(x = Date, y = CFR, col = State.UnionTerritory)) +
geom_line() +
labs(title = "CFR of Indian States/UT",
subtitle = "June onwards",
y = "CFR (%)",
caption = "created by ViSa !!")df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
filter(Date > as.Date("2020-05-31")) %>%
ggplot(aes(x = Date, y = CFR, col = State.UnionTerritory)) +
geom_line(size = 0.8) +
scale_color_tableau() +
gghighlight(CFR > 3) +
labs(title = "CFR of States/UT with CFR > 3%",
subtitle = "(June onwards)",
y = "CFR (%)",
caption = "created by ViSa !!")df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
filter(Date > as.Date("2020-05-31")) %>%
ggplot(aes(x = Date, y = CFR, col = State.UnionTerritory)) +
geom_line(size = 0.8) +
scale_color_tableau() +
gghighlight(State.UnionTerritory %in% c("Delhi","Maharashtra","Karnatka",
"Uttar Pradesh","Haryana","West Bengal")) +
labs(title = "CFR of States June onwards",
subtitle = "Highlighted for selected States",
y = "CFR (%)",
caption = "created by ViSa !!")df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
filter(Date > as.Date("2020-05-31")) %>%
ggplot(aes(x = Date, y = CFR, col = State.UnionTerritory)) +
geom_line(size = 0.8) +
scale_color_tableau() +
gghighlight(State.UnionTerritory %in%
(df_ind %>%
filter(Date == max(Date, na.rm = TRUE)) %>%
top_n(n = 7, wt = CFR) %>%
pull(State.UnionTerritory) )
) +
theme_minimal() +
labs(title = glue("Highlighted Top 7 States/UT with highest CFR as of {max(df_ind$Date, na.rm=TRUE)}"),
subtitle = "CFR of States June onwards",
y = "CFR (%)",
caption = "Created by ViSa !!")ggsave(filename = "Top7_CFR_Indian_States.jpg", dpi = 300, height = 8, width = 10)stream_CFR <- df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
streamgraph(date = "Date", key = "State.UnionTerritory", value = "CFR") %>%
sg_fill_tableau() %>%
# sg_fill_brewer("BuPu") %>%
sg_title("Case Fatality Rate of all Indian States across 2020")
stream_CFRstream_confirmed <- df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
streamgraph(date = "Date", key = "State.UnionTerritory", value = "Daily_confirmed") %>%
sg_fill_tableau() %>%
sg_title(title = "Flow of Daily confirmed cases by all Indian States across 2020")
stream_confirmedAdding annotations, legend from: https://blogs.worldbank.org/opendata/interactive-product-export-streamgraphs-data360r-now-cran
stream_deaths <- df_ind %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***")) %>%
streamgraph(date = "Date", key = "State.UnionTerritory", value = "Daily_deaths") %>%
sg_fill_tableau() %>%
sg_title(title = "Flow of Daily covid deaths reported by all Indian States across 2020")#%>%
# sg_annotate(label="Maharashtra", x=as.Date("2020-09-20"), y=1000, color="#ffffff", size=18) #%>%
# sg_legend(show=TRUE, label= "State: ")%>%
stream_deathsNot saving shiny.tag object
htmlwidgets::saveWidget(stream_CFR, "stream_CFR_states.html")class(stream_CFR)[1] "shiny.tag"
df_ind_stacked_cum %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
# filter(Cases_type == "Confirmed") %>%
group_by(State.UnionTerritory, Cases_type, month) %>%
summarise(Cases_counts = max(Cases_counts, na.rm = TRUE))df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***", "Cases being reassigned to states")) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
filter(Cases_type == "Confirmed") %>%
group_by(State.UnionTerritory, month) %>%
summarise(Cases_counts = max(Cases_counts, na.rm = TRUE)) %>%
group_by(month) %>%
top_n(n = 7, wt = Cases_counts) %>%
ungroup() %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, Cases_counts, max)) %>%
ggplot(aes(x = Cases_counts, y = State.UnionTerritory,
fill = State.UnionTerritory, group = State.UnionTerritory )) +
geom_col() +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90),
legend.position = "none") +
facet_wrap(~month) +
# coord_cartesian(clip = "off") +
scale_fill_tableau(palette = "Tableau 20") +
labs(title = "Confirmed cases: Top 7 States/UT each month",
caption = "Created by ViSa !!") +
scale_x_continuous(label = scales::comma_format())df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***", "Cases being reassigned to states"),
Date > as.Date("2020-04-30")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
filter(Cases_type == "Confirmed") %>%
mutate(ConfPercapita = Cases_counts/Population_State) %>%
group_by(State.UnionTerritory, month) %>%
summarise(ConfPercapita = max(ConfPercapita, na.rm = TRUE)) %>%
group_by(month) %>%
top_n(n = 7, wt = ConfPercapita) %>%
ungroup() %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, ConfPercapita, max)) %>%
ggplot(aes(x = ConfPercapita, y = State.UnionTerritory,
fill = State.UnionTerritory, group = State.UnionTerritory )) +
geom_col() +
theme_clean() +
theme(axis.text.x = element_text(angle = 90),
legend.position = "none") +
facet_wrap(~month) +
# coord_cartesian(clip = "off") +
labs(title = "Confirmed cases Percapita: Top 7 States/UT each month (May onwards)",
subtitle = "Delhi is worst Performed among Metro states & overall recently !!",
y = "",
caption = "Created by ViSa !!") +
scale_x_continuous(labels = scales::percent_format()) +
scale_fill_brewer(palette = "Paired")Top 7 based on: State’s CFR max spike in each month
Exporting csv
write.csv(df_ind_stacked_cum, "df_ind_stacked_cum.csv", row.names = FALSE) df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***", "Cases being reassigned to states")) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
filter(Cases_type == "Confirmed") %>%
group_by(State.UnionTerritory, month) %>%
summarise(CFR = max(CFR, na.rm = TRUE)) %>%
group_by(month) %>%
top_n(n = 7, wt = CFR) %>%
ungroup() %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, CFR, max)) %>%
ggplot(aes(x = CFR, y = State.UnionTerritory,
fill = State.UnionTerritory, group = State.UnionTerritory )) +
geom_col() +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90),
legend.position = "none") +
facet_wrap(~month) +
# coord_cartesian(clip = "off") +
scale_fill_tableau(palette = "Tableau 20") +
labs(title = "Case Fatality Ratio: Top 7 States each month",
subtitle = "Top 7 based on State's CFR max spike in each month",
x = "CFR (%)",
caption = "Created by ViSa !!")df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***", "Cases being reassigned to states"),
Date > as.Date("2020-04-30")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
filter(Cases_type == "Confirmed") %>%
group_by(State.UnionTerritory, month) %>%
summarise(CFR = max(CFR, na.rm = TRUE)) %>%
group_by(month) %>%
top_n(n = 7, wt = CFR) %>%
ungroup() %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, CFR, max)) %>%
ggplot(aes(x = CFR, y = State.UnionTerritory,
fill = State.UnionTerritory, group = State.UnionTerritory )) +
geom_col() +
theme_clean() +
theme(axis.text.x = element_text(angle = 90),
legend.position = "none") +
facet_wrap(~month) +
# coord_cartesian(clip = "off") +
scale_fill_tableau(palette = "Tableau 20") +
labs(title = "CFR: Top 7 States each month (May onwards)",
subtitle = "Top 7 based on State's max CFR spike in each month",
x = "CFR (%)",
caption = "Created by ViSa !!")based on State’s max spike in each month
df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***",
"Cases being reassigned to states")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
filter(Cases_type == "Deaths") %>%
group_by(State.UnionTerritory, month) %>%
summarise(Deaths = max(Cases_counts, na.rm = TRUE)) %>%
group_by(month) %>%
top_n(n = 7, wt = Deaths) %>%
ungroup() %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, Deaths, max)) %>%
ggplot(aes(x = Deaths, y = State.UnionTerritory,
fill = State.UnionTerritory, group = State.UnionTerritory )) +
geom_col() +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90),
legend.position = "none") +
facet_wrap(~month) +
# coord_cartesian(clip = "off") +
scale_fill_tableau(palette = "Tableau 20") +
labs(title = "Deaths: Top 7 States each month",
subtitle = "Top 7 based on State's max Death spike in each month",
caption = "Created by ViSa !!") +
scale_x_continuous(labels = scales::comma_format()) df_ind_stacked_cum %>% pull(Cases_type) %>% table().
Confirmed Cured Deaths
9291 9291 9291
(df_ind_stacked_rates$State.UnionTerritory %>% unique())[1:22] [1] Kerala Telangana Delhi Rajasthan Uttar Pradesh
[6] Haryana Ladakh Tamil Nadu Karnataka Maharashtra
[11] Punjab Jammu and Kashmir Andhra Pradesh Uttarakhand Odisha
[16] Puducherry West Bengal Chhattisgarh Chandigarh Gujarat
[21] Himachal Pradesh Madhya Pradesh
43 Levels: Andaman and Nicobar Islands Andhra Pradesh Arunachal Pradesh Assam ... West Bengal
df_ind_stacked_rates %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***",
"Cases being reassigned to states", "Unassigned")
) %>%
filter(State.UnionTerritory %in% (df_ind_stacked_rates$State.UnionTerritory %>%
unique())[1:22]) %>%
# mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
# filter(Cases_type == "Confirmed") %>%
ggplot(aes(x = Date, y = Rate_value, col = Rate_type)) +
geom_path() +
facet_wrap(~State.UnionTerritory) +
labs(title = "Recovery Rate & CFR of States: Part 1",
y = "log of Rate(%)",
caption = "Created by ViSa !!") +
scale_y_log10()df_ind_stacked_rates %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***",
"Cases being reassigned to states", "Unassigned")
) %>%
filter(State.UnionTerritory %in% (df_ind_stacked_rates$State.UnionTerritory %>%
unique())[23:43]) %>%
# mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
# filter(Cases_type == "Confirmed") %>%
ggplot(aes(x = Date, y = Rate_value, col = Rate_type)) +
geom_path() +
facet_wrap(~State.UnionTerritory) +
labs(title = "Recovery Rate & CFR of States: Part 2",
y = "log of Rate(%)",
caption = "Created by ViSa !!") +
scale_y_log10()df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***",
"Cases being reassigned to states")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
group_by(State.UnionTerritory, month, Cases_type) %>%
summarise(Cases_counts = max(Cases_counts, na.rm = TRUE)) %>%
group_by(month, Cases_type) %>%
top_n(n = 7, wt = Cases_counts) %>% #pull(State.UnionTerritory) %>% unique()
mutate(Cases_size = Cases_counts / sum(Cases_counts)) %>%
write.csv("df_ind_stacked_cum.csv", row.names = FALSE)
df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***",
"Cases being reassigned to states")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
group_by(State.UnionTerritory, month, Cases_type) %>%
summarise(Cases_counts = max(Cases_counts, na.rm = TRUE)) %>%
group_by(month, Cases_type) %>%
top_n(n = 7, wt = Cases_counts) %>% #pull(State.UnionTerritory) %>% unique()
mutate(Cases_size = Cases_counts / sum(Cases_counts)) %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, Cases_counts, max)) %>%
ggplot(aes(x = Cases_type, y = State.UnionTerritory)) +
geom_point(shape = 21, # alpha = 0.6,
aes(size = Cases_size, color = Cases_type), fill = "#FFEBCD", stroke = 3) +
theme_wsj() +
theme(axis.text.x = element_text(angle = 90),
title = element_text(size = 12),
legend.position = "bottom"
) +
facet_wrap(~month) +
coord_cartesian(clip = "off") +
scale_color_tableau(palette = "Tableau 10") +
labs(title = "Top 7 States each month: Confirmed | Recovered | Deaths",
subtitle = "Point Size varies based on respective month cases type within each category
Top 7 based on State's max spike in each category each month",
caption = "Created by ViSa !!") # scale_x_continuous(labels = scales::comma_format())
df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***",
"Cases being reassigned to states")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
group_by(State.UnionTerritory, month, Cases_type) %>%
summarise(Cases_counts = max(Cases_counts, na.rm = TRUE)) %>%
group_by(month, Cases_type) %>%
top_n(n = 5, wt = Cases_counts) %>% #pull(State.UnionTerritory) %>% unique()
mutate(Cases_size = Cases_counts / sum(Cases_counts)) %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, Cases_counts, max)) %>%
ggplot(aes(x = Cases_type, y = State.UnionTerritory)) +
geom_point(shape = 21, # alpha = 0.6,
aes(size = Cases_size, color = Cases_type), fill = "#FFEBCD", stroke = 3) +
theme_wsj() +
theme(axis.text.x = element_text(angle = 90),
title = element_text(size = 12),
legend.position = "bottom"
) +
facet_wrap(~month) +
coord_cartesian(clip = "off") +
scale_color_tableau(palette = "Tableau 10") +
labs(title = "Top 5 States each month: Confirmed | Recovered | Deaths",
subtitle = "Point Size varies based on respective month cases type within each category
Top 5 based on State's max spike in each category each month",
caption = "Created by ViSa !!") # scale_x_continuous(labels = scales::comma_format()) df_ind_stacked_rates %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***",
"Cases being reassigned to states")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
group_by(State.UnionTerritory, month) %>%
summarise(New_CFR = round(sum(Deaths) / sum(Confirmed), digits = 4),
New_Recovery_Rate = round(sum(Cured) / sum(Confirmed), digits = 4)) %>%
# mutate(New_CFR = replace(New_CFR, is.na(New_CFR), 0),
# New_Recovery_Rate = replace(New_Recovery_Rate, is.na(New_Recovery_Rate), 0)) %>%
gather(key = Rate_type, value = Rate_value, -c("State.UnionTerritory", "month")) %>%
mutate(Rate_type = replace(Rate_type, Rate_type == "New_CFR","CFR"),
Rate_type = replace(Rate_type, Rate_type == "New_Recovery_Rate","Recovery_Rate"),
Rate_type = as.factor(Rate_type)) %>%
group_by(month, Rate_type) %>%
top_n(n = 3, wt = Rate_value) %>%
mutate(Cases_size = Rate_value / sum(Rate_value),
Cases_size = replace(Cases_size, is.na(Cases_size), 0)) %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, Rate_value, max)) %>%
mutate(State.UnionTerritory = as.character(State.UnionTerritory),
State.UnionTerritory = replace(State.UnionTerritory,
State.UnionTerritory == "Dadra and Nagar Haveli and Daman and Diu",
"Dadra Daman& Diu"),
State.UnionTerritory = as.factor(State.UnionTerritory)) %>%
ungroup() %>% #pull(State.UnionTerritory) %>% unique()
ggplot(aes(x = Rate_type, y = State.UnionTerritory)) +
geom_point(shape = 21, # alpha = 0.6,
aes(size = Cases_size, color = Rate_type), fill = "#FFEBCD", stroke = 3) +
theme_wsj() +
theme(axis.text.x = element_text(angle = 90),
title = element_text(size = 12),
legend.position = "bottom",
axis.text.y = element_text(size = 12)
) +
facet_wrap(~month) +
coord_cartesian(clip = "off") +
scale_color_tableau(palette = "Tableau 10") +
labs(title = "Top 3 States each month: Case Fatality Rate | Recovery Rate",
subtitle = "Point Size varies based on respective month cases type within each category",
caption = "Created by ViSa !!") # scale_x_continuous(labels = scales::comma_format())
df_ind_stacked_rates %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***",
"Cases being reassigned to states")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
group_by(State.UnionTerritory, month) %>%
summarise(New_CFR = round(sum(Deaths) / sum(Confirmed), digits = 4),
New_Recovery_Rate = round(sum(Cured) / sum(Confirmed), digits = 4)) %>%
# mutate(New_CFR = replace(New_CFR, is.na(New_CFR), 0),
# New_Recovery_Rate = replace(New_Recovery_Rate, is.na(New_Recovery_Rate), 0)) %>%
gather(key = Rate_type, value = Rate_value, -c("State.UnionTerritory", "month")) %>%
mutate(Rate_type = replace(Rate_type, Rate_type == "New_CFR","CFR"),
Rate_type = replace(Rate_type, Rate_type == "New_Recovery_Rate","Recovery_Rate"),
Rate_type = as.factor(Rate_type)) %>%
group_by(month, Rate_type) %>%
# top_n(n = 3, wt = Rate_value) %>%
mutate(Cases_size = Rate_value / sum(Rate_value),
Cases_size = replace(Cases_size, is.na(Cases_size), 0)) %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, Rate_value, max)) %>%
mutate(State.UnionTerritory = as.character(State.UnionTerritory),
State.UnionTerritory = replace(State.UnionTerritory,
State.UnionTerritory == "Dadra and Nagar Haveli and Daman and Diu",
"Dadra Daman& Diu"),
State.UnionTerritory = as.factor(State.UnionTerritory)) %>%
ungroup() %>%
filter(month == "May", Rate_type == "CFR") %>%
arrange(desc(Rate_value))df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***", "Cases being reassigned to states"),
Date > as.Date("2020-04-30")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
filter(Cases_type == "Confirmed") %>%
group_by(State.UnionTerritory, month) %>%
summarise(Cases_counts = max(Cases_counts, na.rm = TRUE),
CFR = last(CFR)) %>%
group_by(month) %>%
top_n(n = 7, wt = CFR) %>%
ungroup() %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, CFR, max)) %>%
# filter(month == "May")
ggplot(aes(x = CFR, y = State.UnionTerritory,
fill = State.UnionTerritory, group = State.UnionTerritory )) +
geom_col() +
theme_clean() +
theme(axis.text.x = element_text(angle = 90),
legend.position = "none") +
facet_wrap(~month) +
# coord_cartesian(clip = "off") +
scale_fill_tableau(palette = "Tableau 20") +
labs(title = "CFR: Top 7 States each month (May onwards)",
x = "CFR (%)",
caption = "Created by ViSa !!")df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***", "Cases being reassigned to states"),
Date > as.Date("2020-04-30")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
filter(Cases_type == "Confirmed") %>%
group_by(State.UnionTerritory, month) %>%
filter(month == "May", State.UnionTerritory == "Puducherry")Finding Last dates of months
from: https://www.roelpeters.be/get-the-first-day-or-the-last-day-of-the-month-in-r-using-lubridate/
df_ind_stacked_cum %>%
pull(Date) %>%
unique() %>%
ymd() %>%
ceiling_date("month")-1 [1] "2020-01-31" "2020-01-31" "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29"
[8] "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29"
[15] "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29"
[22] "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29" "2020-02-29"
[29] "2020-02-29" "2020-02-29" "2020-02-29" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31"
[36] "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31"
[43] "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31"
[50] "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31"
[57] "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-03-31" "2020-04-30"
[64] "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30"
[71] "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30"
[78] "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30"
[85] "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30" "2020-04-30"
[92] "2020-04-30" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31"
[99] "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31"
[106] "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31"
[113] "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31"
[120] "2020-05-31" "2020-05-31" "2020-05-31" "2020-05-31" "2020-06-30" "2020-06-30" "2020-06-30"
[127] "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30"
[134] "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30"
[141] "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30"
[148] "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-06-30" "2020-07-31"
[155] "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31"
[162] "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31"
[169] "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31"
[176] "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31" "2020-07-31"
[183] "2020-07-31" "2020-07-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31"
[190] "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31"
[197] "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31"
[204] "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31"
[211] "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-08-31" "2020-09-30" "2020-09-30"
[218] "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30"
[225] "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30"
[232] "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30"
[239] "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30" "2020-09-30"
[246] "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31"
[253] "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31"
[260] "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31"
[267] "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31" "2020-10-31"
[274] "2020-10-31" "2020-10-31" "2020-10-31" "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30"
[281] "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30"
[288] "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30"
[295] "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30"
[302] "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30" "2020-11-30" "2020-12-31" "2020-12-31"
[309] "2020-12-31" "2020-12-31" "2020-12-31" "2020-12-31" "2020-12-31" "2020-12-31" "2020-12-31"
df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***", "Cases being reassigned to states"),
Date > as.Date("2020-04-30")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
filter(Cases_type == "Confirmed",
Date == ceiling_date(Date, "month") -1) %>%
group_by(State.UnionTerritory, month) %>%
summarise(CFR = max(CFR, na.rm = TRUE)) %>%
group_by(month) %>%
top_n(n = 7, wt = CFR) %>%
ungroup() %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, CFR, max)) %>%
# filter(month == "May")
ggplot(aes(x = CFR, y = State.UnionTerritory,
fill = State.UnionTerritory, group = State.UnionTerritory )) +
geom_col() +
theme_clean() +
theme(axis.text.x = element_text(angle = 90),
legend.position = "none") +
facet_wrap(~month) +
# coord_cartesian(clip = "off") +
scale_fill_tableau(palette = "Tableau 20") +
labs(title = "CFR: Top 7 States each month (May onwards)",
x = "CFR (%)",
caption = "Created by ViSa !!")df_ind_stacked_cum %>%
filter(!State.UnionTerritory %in%
c("Maharashtra***","Punjab***","Chandigarh***","Telangana***", "Cases being reassigned to states"),
Date > as.Date("2020-04-30")
) %>%
mutate(month = lubridate::month(Date, label = TRUE, abbr = TRUE)) %>%
filter(Cases_type == "Confirmed",
Date == ceiling_date(Date, "month") -1) %>%
group_by(State.UnionTerritory, month) %>%
summarise(CFR = max(CFR, na.rm = TRUE)) %>%
group_by(month) %>% #filter(month == "May") %>% arrange(desc(CFR))
top_n(n = 7, wt = CFR) %>%
ungroup() %>%
mutate(State.UnionTerritory = fct_reorder(State.UnionTerritory, CFR, max)) %>%
# filter(month == "May")
ggplot(aes(x = CFR, y = State.UnionTerritory,
fill = State.UnionTerritory, group = State.UnionTerritory )) +
geom_col() +
theme_clean() +
theme(axis.text.x = element_text(angle = 90),
legend.position = "none") +
facet_wrap(~month) +
# coord_cartesian(clip = "off") +
scale_fill_tableau(palette = "Tableau 20") +
labs(title = "CFR: Top 7 States each month (May onwards)",
x = "CFR (%)",
caption = "Created by ViSa !!")df_ind %>% filter(Daily_confirmed < 0)Cumulative Numbers falls for few states and creates negative daily_confirmed cases.
df_ind %>%
filter(Date %in% c(as.Date("2020-03-09") : as.Date("2020-03-14")),
State.UnionTerritory == "Maharashtra")Calculation in CFR gets mismatched numbers when calculated by: 1. CFR calculated on daily basis and selected CFR on max(Confirmed) of month which should be correct if cumulative of figures is correct.
from:
https://jkunst.com/highcharter/articles/maps.html
https://code.highcharts.com/mapdata/
https://jkunst.com/highcharter/reference/download_map_data.html
hcmap("countries/in/in-all")df_ind_map <- get_data_from_map(download_map_data("https://code.highcharts.com/mapdata/countries/in/in-all.js"))trying URL 'https://code.highcharts.com/mapdata/countries/in/in-all.js'
Content type 'text/javascript' length 52340 bytes (51 KB)
downloaded 51 KB
glimpse(df_ind_map)Rows: 34
Columns: 20
$ `hc-group` <chr> "admin1", "admin1", "admin1", "admin1", "admin1", "admin1", "admin1", "admin1...
$ `hc-middle-x` <dbl> 0.65, 0.59, 0.50, 0.56, 0.46, 0.46, 0.51, 0.59, 0.47, 0.56, 0.60, 0.63, 0.51,...
$ `hc-middle-y` <dbl> 0.81, 0.63, 0.74, 0.38, 0.64, 0.51, 0.34, 0.41, 0.60, 0.32, 0.47, 0.55, 0.48,...
$ `hc-key` <chr> "in-py", "in-ld", "in-wb", "in-or", "in-br", "in-sk", "in-ct", "in-tn", "in-m...
$ `hc-a2` <chr> "PY", "LD", "WB", "OR", "BR", "SK", "CT", "TN", "MP", "GU", "GA", "NL", "MN",...
$ labelrank <chr> "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2...
$ hasc <chr> "IN.PY", "IN.LD", "IN.WB", "IN.OR", "IN.BR", "IN.SK", "IN.CT", "IN.", "IN.MP"...
$ `alt-name` <chr> "Pondicherry|Puduchcheri|Pondichéry", "Íles Laquedives|Laccadive|Minicoy and ...
$ `woe-id` <chr> "20070459", "2345748", "2345761", "2345755", "2345742", "2345762", "20070464"...
$ fips <chr> "IN22", "IN14", "IN28", "IN21", "IN34", "IN29", "IN37", "IN22", "IN35", "IN32...
$ `postal-code` <chr> "PY", "LD", "WB", "OR", "BR", "SK", "CT", "TN", "MP", NA, "GA", "NL", "MN", "...
$ name <chr> "Puducherry", "Lakshadweep", "West Bengal", "Orissa", "Bihar", "Sikkim", "Chh...
$ country <chr> "India", "India", "India", "India", "India", "India", "India", "India", "Indi...
$ `type-en` <chr> "Union Territory", "Union Territory", "State", "State", "State", "State", "St...
$ region <chr> "South", "South", "East", "East", "East", "East", "Central", "South", "Centra...
$ longitude <chr> "79.7758", "72.7811", "87.7289", "84.4341", "85.8134", "88.4482", "82.3069", ...
$ `woe-name` <chr> "Puducherry", "Lakshadweep", "West Bengal", "Orissa", "Bihar", "Sikkim", "Chh...
$ latitude <chr> "10.9224", "11.2249", "23.0523", "20.625", "25.6853", "27.5709", "21.8044", "...
$ `woe-label` <chr> "Puducherry, IN, India", "Lakshadweep, IN, India", "West Bengal, IN, India", ...
$ type <chr> "Union Territor", "Union Territor", "State", "State", "State", "State", "Stat...
df_ind_map %>%
select(`hc-a2`, name)data_fake <- df_ind_map %>%
select(code = "hc-a2") %>%
mutate(value = 1e6 * abs(rt(nrow(.), df = 10)))
glimpse(data_fake)Rows: 34
Columns: 2
$ code <chr> "PY", "LD", "WB", "OR", "BR", "SK", "CT", "TN", "MP", "GU", "GA", "NL", "MN", "AR", "...
$ value <dbl> 2593212.71, 143636.99, 93399.94, 327319.66, 554691.31, 824416.34, 830512.10, 2102316....
hcmap(
"countries/in/in-all",
data = data_fake,
value = "value",
joinBy = c("hc-a2", "code"),
name = "Fake data",
datalabels = list(enabled = TRUE, format = "{point.name}"),
borderColor = "#FAFAFA",
borderWidth = 0.1,
tooltip = list(
valueDecimals = 2,
valuePrefix = "$")
)trying URL 'https://code.highcharts.com/mapdata/countries/in/in-all.js'
Content type 'text/javascript' length 52340 bytes (51 KB)
downloaded 51 KB
intersect(df_ind$State.UnionTerritory, df_ind_map$name) [1] "Kerala" "Delhi" "Rajasthan" "Uttar Pradesh" "Haryana"
[6] "Tamil Nadu" "Karnataka" "Maharashtra" "Punjab" "Jammu and Kashmir"
[11] "Andhra Pradesh" "Puducherry" "West Bengal" "Chhattisgarh" "Chandigarh"
[16] "Gujarat" "Himachal Pradesh" "Madhya Pradesh" "Bihar" "Manipur"
[21] "Mizoram" "Goa" "Assam" "Jharkhand" "Arunachal Pradesh"
[26] "Tripura" "Nagaland" "Meghalaya" "Sikkim"
dim(df_ind)[1] 9291 15
df_ind <- left_join(x = df_ind, y = (df_ind_map %>% select(name,`hc-a2`)),
by = c("State.UnionTerritory" = "name"))
df_indTelangana, Ladakh couldn’t be find
df_ind[which(df_ind$State.UnionTerritory == "Daman & Diu"), "hc-a2"] <- "DA"
df_ind[which(df_ind$State.UnionTerritory == "Odisha"), "hc-a2"] <- "OR"
df_ind[which(df_ind$State.UnionTerritory == "Dadra and Nagar Haveli and Daman and Diu"), "hc-a2"] <- "DN"
df_ind[which(df_ind$State.UnionTerritory == "Uttarakhand"), "hc-a2"] <- "UT"hcmap(
"countries/in/in-all",
data = (df_ind %>% filter(Date == max(Date, na.rm = TRUE))),
value = "Confirmed",
joinBy = c("hc-a2"),
name = "Confirmed Cases",
datalabels = list(enabled = TRUE, format = "{point.name}"),
borderColor = "#FAFAFA",
borderWidth = 0.1,
tooltip = list(
# valueDecimals = 2,
# valuePrefix = "$"
)
) %>%
hc_title(text = "Confirmed Cases Statewise across India")trying URL 'https://code.highcharts.com/mapdata/countries/in/in-all.js'
Content type 'text/javascript' length 52340 bytes (51 KB)
downloaded 51 KB
hcmap(
"countries/in/in-all",
data = (df_ind %>%
filter(Date == max(Date, na.rm = TRUE)) %>%
mutate(CasesPercapPerc = Confirmed/Population_State * 100)),
value = "CasesPercapPerc",
joinBy = c("hc-a2"),
name = "Confirmed Cases Per Capita (%)",
datalabels = list(enabled = TRUE, format = "{point.name}"),
borderColor = "#FAFAFA",
borderWidth = 0.1,
tooltip = list(
valueDecimals = 2,
valueSuffix = " %"
)
) %>%
hc_title(text = "Confirmed Cases Per Capita(%) Statewise across India") %>%
hc_subtitle(text = "Delhi has highest Confirmed Cases Per Capita(%) India") %>%
hc_caption(text = "created by ViSa!!")trying URL 'https://code.highcharts.com/mapdata/countries/in/in-all.js'
Content type 'text/javascript' length 52340 bytes (51 KB)
downloaded 51 KB
hcmap(
"countries/in/in-all",
data = (df_ind %>%
filter(Date == max(Date, na.rm = TRUE)) %>%
mutate(CasesPercapPerc = Confirmed/Population_State * 100)),
value = "CasesPercapPerc",
joinBy = c("hc-a2"),
name = "Confirmed Cases Per Capita (%)",
datalabels = list(enabled = TRUE, format = "{point.name}"),
borderColor = "#FAFAFA",
borderWidth = 0.1,
tooltip = list(
valueDecimals = 2,
valueSuffix = " %"
)
) %>%
hc_colorAxis(stops = color_stops()) %>%
hc_title(text = "Confirmed Cases Per Capita(%) Statewise across India") %>%
hc_subtitle(text = "Delhi has highest Confirmed Cases Per Capita(%) India") %>%
hc_caption(text = "created by ViSa!!")trying URL 'https://code.highcharts.com/mapdata/countries/in/in-all.js'
Content type 'text/javascript' length 52340 bytes (51 KB)
downloaded 51 KB
from: https://www.datanovia.com/en/lessons/highchart-interactive-world-map-in-r/
hcmap(
"countries/in/in-all",
data = (df_ind %>%
filter(Date == max(Date, na.rm = TRUE)) %>%
mutate(CasesPercapPerc = Confirmed/Population_State * 100)),
value = "CasesPercapPerc",
joinBy = c("hc-a2"),
name = "Confirmed Cases Per Capita (%)",
datalabels = list(enabled = TRUE, format = "{point.name}"),
borderColor = "#FAFAFA",
borderWidth = 0.1,
tooltip = list(
valueDecimals = 2,
valueSuffix = " %"
)
) %>%
hc_colorAxis(minColor = "purple", maxColor = "red") %>%
hc_title(text = "Confirmed Cases Per Capita(%) Statewise across India") %>%
hc_subtitle(text = "Delhi has highest Confirmed Cases Per Capita(%) India") %>%
hc_caption(text = "created by ViSa!!")trying URL 'https://code.highcharts.com/mapdata/countries/in/in-all.js'
Content type 'text/javascript' length 52340 bytes (51 KB)
downloaded 51 KB
hcmap(
"countries/in/in-all",
data = (df_ind %>%
filter(Date == max(Date, na.rm = TRUE))
),
value = "CFR",
joinBy = c("hc-a2"),
name = "CFR(%)",
datalabels = list(enabled = TRUE, format = "{point.name}"),
borderColor = "#FAFAFA",
borderWidth = 0.1,
tooltip = list(
valueDecimals = 2,
valueSuffix = " %"
)
) %>%
hc_title(text = "CFR(%) Statewise across India") %>%
hc_subtitle(text = "Punjab, Maharashtra has highest CFR(%) India") %>%
hc_caption(text = "created by ViSa!!")trying URL 'https://code.highcharts.com/mapdata/countries/in/in-all.js'
Content type 'text/javascript' length 52340 bytes (51 KB)
downloaded 51 KB
hcmap(
"countries/in/in-all",
data = (df_ind %>%
filter(Date == max(Date, na.rm = TRUE))
),
value = "CFR",
joinBy = c("hc-a2"),
name = "CFR(%)",
datalabels = list(enabled = TRUE, format = "{point.name}"),
borderColor = "#FAFAFA",
borderWidth = 0.1,
tooltip = list(
valueDecimals = 2,
valueSuffix = " %"
)
) %>%
hc_colorAxis(stops = color_stops()) %>%
hc_title(text = "CFR(%) Statewise across India") %>%
hc_subtitle(text = "Punjab, Maharashtra has highest CFR(%) India") %>%
hc_caption(text = "created by ViSa!!")trying URL 'https://code.highcharts.com/mapdata/countries/in/in-all.js'
Content type 'text/javascript' length 52340 bytes (51 KB)
downloaded 51 KB